#ifndef _FDPOLL_H_
#define _FDPOLL_H_

#include "netfwd.h"

#pragma once

class FDPoll
{
public:
    enum FDOpTypeEnum
    {
        EOPTYPE_NO      = 0x00,
        EOPTYPE_IN      = 0x01,
        EOPTYPE_OUT     = 0x02,
        EOPTYPE_PRI     = 0x04,
        EOPTYPE_ERROR   = 0x08,
        EOPTYPE_HUP     = 0x10
    };

    typedef int32_t Fd;

    FDPoll();

    ~FDPoll() throw();

    int32_t get_maxfd() const;

    int32_t add( Fd infd, int32_t optype, void * userdata );

    int32_t set( Fd infd, int32_t optype, void * userdata );

    inline int32_t in( Fd infd, void * userdata )
    {
        return set( infd, EOPTYPE_IN, userdata );
    }

    inline int32_t out( Fd infd, void * userdata )
    {
        return set( infd, EOPTYPE_OUT, userdata );
    }

    inline int32_t io( Fd infd, void * userdata )
    {
        return set( infd, EOPTYPE_IN | EOPTYPE_OUT, userdata );
    }

    int32_t remove( int32_t fd );

    int32_t poll( int32_t waitmillisec );

    int32_t next( int32_t & optype, void *& userdata );

private:
    class Impl;
    Impl * m_impl;

private:
    FDPoll( const FDPoll & );
    const FDPoll & operator= ( const FDPoll & );
};

#endif // _FDPOLL_H_

